//
//  MJRegisterViewModel.m
//  MJ
//
//  Created by qiaoBu on 2017/12/11.
//  Copyright © 2017年 lina. All rights reserved.
//

#import "MJRegisterViewModel.h"
#import "MJNetWorkTool.h"

@implementation MJRegisterViewModel

+ (void)requestRegisterWithDict:(NSMutableDictionary *)parameters Success:(void (^)(NSString *state,NSString *message))requestSuccess failure:(void(^)(NSError *error))requestFailure netWorkState:(void (^) (BOOL netWorkState))netWorkState{
    
    [[MJNetWorkTool sharedUtil] requestAFURL:MJ_Me_Register httpMethod:1 parameters:parameters succeed:^(id dict) {
        
        
        NSDictionary *resultDict = [NSDictionary dictionaryWithDictionary:dict];
        NSString *stateCode = [resultDict objectForKey:@"flag"];
        
        if ([stateCode isEqualToString:@"001"])
        {
            NSString *userTicket = [NSString stringWithFormat:@"%@",[[resultDict objectForKey:@"content"] objectForKey:@"ticket"]];
            [[NSUserDefaults standardUserDefaults] setObject:userTicket forKey:MJ_Ticket];
            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:IsLogined];
            [[NSUserDefaults standardUserDefaults] synchronize];
            requestSuccess(stateCode,nil);
        }
        else
        {
            requestSuccess(stateCode,[resultDict objectForKey:@"content"]);
        }
    } failure:^(NSError *err) {
        requestFailure (err);
    }];
}

@end
